<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div id="date"></div>
    <script>
        var end = new Date("2021-12-12 00:00");

        function countDown() {
            var now = new Date();
            var day, hour, minute, second, str, remainder = end - now;

            if (remainder < 0) {
                return;
            }

            day = Math.floor(remainder / 1000 / 60 / 60 / 24);
            hour = Math.floor(remainder / 1000 / 60 / 60 % 24);
            minute = Math.floor(remainder / 1000 / 60 % 60);
            second = Math.floor(remainder / 1000 % 60)
            str = day + "天" + hour + "时" + minute + "分" + second + "秒";
            document.getElementById("date").innerHTML = str;
            setTimeout(countDown, 1000);
        }

        countDown();
    </script>
</body>

</html>